<template>
	<w-container class='page-bg pt-16' :loading="loading">
		<w-navbar navType="default" id="my-nav" title="当前竞价"></w-navbar>
		<BegBuyList ref="begList" :product="product" :id='id' />
		<view class="action plr-16">
			<w-button type="colorful" shape="circle" @click='toBeg'>我要竞价</w-button>
		</view>
	</w-container>
</template>

<script>
	import BegBuyList from './components/BegBuyList.vue'
	import {
		getMarketGoodsInfo
	} from '@/api/market/index.js'
	export default {
		data() {
			return {
				id: '',
				product: {},
				goodsType: null,
				loading: true
			}
		},
		components: {
			BegBuyList
		},
		methods: {
			async getInfo() {
				this.loading = true;

				try {
					let {
						data
					} = await getMarketGoodsInfo({
						id: this.id,
						type: this.goodsType
					})
					this.product = data;
				} catch {
					setTimeout(() => {
						uni.navigateBack({
							delta: 1
						})
					}, 500)
				} finally {
					this.loading = false;
				}
			},
			toBeg(){
				uni.navigateTo({
					url: '/pages/market/submitBegBuy?id=' + this.id
				})
			}
		},
		onLoad({
			id,
			goodsType
		}) {
			this.id = id
			this.goodsType = goodsType
			this.getInfo()
		},
		onPullDownRefresh() {
			this.$refs.begList.getList(this.$refs.begList.search).then(() => {
				uni.stopPullDownRefresh()
			})
		},
		onReachBottom() {
			this.$refs.begList.loadMore()
		}
	}
</script>

<style lang="scss">
	.action {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 750rpx;
		padding-top: 32rpx;
		padding-bottom: calc(env(safe-area-inset-bottom) + 32rpx);
		background-color: #fff;
	}
</style>